$(()=> {
  var myChart = echarts.init(document.getElementById('main'));
  
  let xData = [],
      yData = [];
for(let i=0; i<=1; i+=0.1){
  xData.push(roundF(i, 2));
  yData.push(roundF(h(i), 2));
}
yData[0] = 0;
function h(p){
  return -1*p*Math.log2(p)-(1-p)*Math.log2(1-p);
}
function roundF(x, n){
  return Math.round(x * Math.pow(10, n)) / Math.pow(10, n);
}
  option = {
    title: {
      text: '二进熵函数曲线'
    },
    tooltip:{},
    xAxis: {
      data: xData
    },
    yAxis: {},
    series: [{
      name: '信息量',
      data: yData,
      type: 'line',
      smooth: true  
    }]
  };

  myChart.setOption(option);
});
